/**
 * 
 */
package reinvent.d.wheel.UM.dao.impl;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceException;

import org.springframework.orm.jpa.JpaCallback;
import org.springframework.orm.jpa.support.JpaDaoSupport;

import reinvent.d.wheel.UM.dao.UserDao;
import reinvent.d.wheel.UM.entity.User;
import reinvent.d.wheel.UM.exception.UserdefinitionNotTrueException;

/**
 * @author nishant.awasthi
 *
 */
public class UserDaoImpl extends JpaDaoSupport implements UserDao {

	/**
	 * 
	 */
	public UserDaoImpl() {
		// TODO Auto-generated constructor stub
	}

	/* (non-Javadoc)
	 * @see reinvent.d.wheel.UM.dao.UserDao#createUser(java.lang.String, java.lang.String, java.lang.String)
	 */
	public User createUser(final String uname, final String password, final String email) {
		this.getJpaTemplate().execute(new JpaCallback<User> (){

			public User doInJpa(EntityManager em) throws PersistenceException {
				User u=null;
				try {
					u= new User(uname, password, email);
				} catch (UserdefinitionNotTrueException e) {
					throw new PersistenceException(e.getMessage(),e);
				}
				em.persist(u);
				return null;
			}
			
		});
		return null;
	}

	/* (non-Javadoc)
	 * @see reinvent.d.wheel.UM.dao.UserDao#deleteUser(java.lang.String)
	 */
	public User deleteUser(String uname) {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see reinvent.d.wheel.UM.dao.UserDao#getUser(java.lang.String)
	 */
	public User getUser(String uname) {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see reinvent.d.wheel.UM.dao.UserDao#updateUser(java.lang.String, java.lang.String, java.lang.String)
	 */
	public User updateUser(String uname, String password, String email) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
